﻿#region Imports
using System;
using System.IO;
#endregion

namespace BulkRenamer.Common.Models
{
    /// <summary>
    /// Holds file details information
    /// </summary>
    [Serializable]
    public class FileDetails
    {
        #region Properties
        /// <summary>
        /// Unique Id of file
        /// </summary>
        public int FileId { get; set; }

        /// <summary>
        /// Full physical path of file (absolute path)
        /// </summary>
        public string FullPath { get; set; }

        /// <summary>
        /// File extension
        /// </summary>
        public string FileExtn { get; set; }

        /// <summary>
        /// Original file name
        /// </summary>
        public string NameOrg { get; set; }

        /// <summary>
        /// Suggested file name (temp)
        /// </summary>
        public string NameSuggTemp { get; set; }

        /// <summary>
        /// Suggested file name
        /// </summary>
        public string NameSuggested { get; set; }

        /// <summary>
        /// Custom file name
        /// </summary>
        public string NameCustom { get; set; }

        /// <summary>
        /// Specifies if suggested/custom name is considered during file name update
        /// <para>TRUE: Suggested name is considered</para>
        /// <para>FALSE: Custom name is considered</para>
        /// </summary>
        public bool TakeSuggested { get; set; }
        #endregion

        public bool IsNameSelected { get; set; }

        #region Constructors
        /// <summary>
        /// Default constructor
        /// </summary>
        public FileDetails() { ; }

        /// <summary>
        /// Parameterized constructor
        /// </summary>
        /// <param name="fileId">File Id</param>
        /// <param name="fileName">File name</param>
        /// <param name="isAnyExtnChecked">TRUE: Specifies if all extn. are considered</param>
        /// <param name="selectedExtn">Selected extn. if not "any" is checked
        /// <para>(<code><paramref name="isAnyExtnChecked"/> = false</code>)</para></param>
        private FileDetails(int fileId, string fileName, bool isAnyExtnChecked, string selectedExtn)
        {
            this.FileId = fileId;
            this.FullPath = fileName;
            this.NameCustom = this.NameSuggested = this.NameOrg = Path.GetFileNameWithoutExtension(fileName);
            this.FileExtn = isAnyExtnChecked ? Path.GetExtension(fileName).TrimStart('.') : selectedExtn; // Path.GetExtension(fileName)
            this.TakeSuggested = true;
        }

        /// <summary>
        /// Parameterized constructor
        /// </summary>
        /// <param name="fileName">File name</param>
        /// <param name="isAnyExtnChecked">TRUE: Specifies if all extn. are considered</param>
        /// <param name="selectedExtn">Selected extn. if not "any" is checked
        /// <para>(<code><paramref name="isAnyExtnChecked"/> = false</code>)</para></param>
        private FileDetails(string fileName, bool isAnyExtnChecked, string selectedExtn)
        {
            this.FullPath = fileName;
            this.NameCustom = this.NameSuggested = this.NameOrg = Path.GetFileNameWithoutExtension(fileName);
            this.FileExtn = isAnyExtnChecked ? Path.GetExtension(fileName).TrimStart('.') : selectedExtn; // Path.GetExtension(fileName)
            this.TakeSuggested = true;
        }
        #endregion

        #region Methods
        /// <summary>
        /// Factory method
        /// </summary>
        /// <param name="fileName">File name</param>
        /// <param name="isAnyExtnChecked">TRUE: Specifies if all extn. are considered</param>
        /// <param name="selectedExtn">Selected extn. if not "any" is checked
        /// <para>(<code><paramref name="isAnyExtnChecked"/> = false</code>)</para></param>
        /// <returns></returns>
        public static FileDetails CreateItem(string fileName, bool isAnyExtnChecked, string selectedExtn)
        {
            return new FileDetails(fileName, isAnyExtnChecked, selectedExtn);
        }
        #endregion
    }
}
